package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView

import com.erp.R
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_xiangxi_item.view.*

/**
 * Cr eated by Administrator on 2017/1/17/017.
 * 作者：刘洋
 */
class XiangxiGvAdapter(private val mdata: Array<String>, private val mtitle: Array<String>, private val mcontext: Context) : BaseAdapter() {
    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)

    override fun getCount(): Int {
        return mdata.size
    }

    override fun getItem(position: Int): Any {
        return mdata[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v :View
        val vh: ViewHolder
        if (convertView == null) {
            v = minflater.inflate(R.layout.lv_xiangxi_item, null)
            vh = ViewHolder(v)
            v.tag = vh
        } else {
            v = convertView
            vh = convertView.tag as ViewHolder
        }
        Myutil.settv(mtitle[position], vh.tvXiangxiTitle)
        Myutil.settv(mdata[position], vh.tvXiangxiData)
        return v
    }

    internal inner class ViewHolder(v: View) {
        var tvXiangxiTitle: TextView = v.tv_xiangxi_title
        var tvXiangxiData: TextView = v.tv_xiangxi_data
    }
}
